package com.bs.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.bs.bean.Person;
import com.bs.dao.PersonDAO;

public class PersonDAOImpl extends SqlMapClientDaoSupport implements PersonDAO {

	@Override
	public int delete(Person person) {
		return this.getSqlMapClientTemplate().delete("person.delete",person);
	}

	
	
	@Override
	public int batchDelete(String ids) {
		return this.getSqlMapClientTemplate().delete("person.batchDelete",ids);
	}



	@SuppressWarnings("unchecked")
	@Override
	public List<Person> findForPaging(int start,int limit) {
		Map<String,Integer> map = new HashMap<String,Integer>();
		map.put("start", start);
		map.put("limit", limit);
		return this.getSqlMapClientTemplate().queryForList("person.findForPaging",map);
	}

	@Override
	public void save(Person person) throws DataAccessException {
		this.getSqlMapClientTemplate().insert("person.save", person);
	}
	

	@Override
	public int getMaxId() {
		return (Integer) this.getSqlMapClientTemplate().queryForList("person.getMaxId").get(0);
	}

	@Override
	public Person findById(int id) {
		return (Person) this.getSqlMapClientTemplate().queryForObject("person.findById",id);
	}

	@Override
	public int totalCount() {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("person.totalCount");
	}

	@Override
	public Person findBySupportType(String supportType) {
		return (Person) this.getSqlMapClientTemplate().queryForObject("person.findBySupportType",supportType);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Person> query(Person person) {
		return this.getSqlMapClientTemplate().queryForList("person.query",person);
	}

	@Override
	public int update(Person person) {
		return this.getSqlMapClientTemplate().update("person.update",person);
	}
	
	
	
}
